package be.vanderveer.services.webthumb.tests;

import static org.junit.Assert.*;
import java.net.URISyntaxException;
import org.junit.Test;
import be.vanderveer.services.webthumb.WebThumb;
import be.vanderveer.services.webthumb.WebThumbJobResponse;
import be.vanderveer.services.webthumb.WebThumbStatusResponse;
import be.vanderveer.services.webthumb.WebThumbStatusResponse.Status;

public class WebThumbTestCase {

	/**
	 * Test method for
	 * {@link be.vanderveer.services.webthumb.WebThumb#requestScreenshot(java.net.URI)}.
	 * Test method for
	 * {@link be.vanderveer.services.webthumb.WebThumb#checkImages(String)}.
	 */
	@Test
	public void testRequestScreenshotURI() {
		final WebThumb webThumb = new WebThumb("e0fea3acf2e225ffe3a72db74ed9b4db");
		WebThumbJobResponse requestresponse = null;
		try {
			requestresponse = webThumb.requestScreenshot("http://www.vanderveer.be");
			System.out.println(requestresponse);
		} catch (final URISyntaxException e) {
			fail("The url is wrong! (" + e.getMessage() + ")");
		}
		WebThumbStatusResponse statusresponse = webThumb.checkImages(requestresponse.getWebThumbId());
		System.out.println(statusresponse);
		while (!statusresponse.getStatus().equals(Status.COMPLETE)) {
			try {
				Thread.sleep(requestresponse.getEstimate()*1000);
			} catch (final InterruptedException e) {
				fail("Sleeping failed! (" + e.getMessage() + ")");
			}
			statusresponse = webThumb.checkImages(requestresponse.getWebThumbId());
			System.out.println(statusresponse);
		}
	}
}
